// JavaScript Document
//焦点图轮播器
var Slide = function(o){
	this.dom = {img:'#slide div',btn:'#slide b',cls:'on',e:'mouseenter',t:3000};
	this.timeout;
	this.index = 0;
	$.extend(this.dom,o);
	this.init();
	this.automatic();
}

Slide.prototype = {
constructor:Slide,
			init:function(){
				var _self = this,_nowshow = $(_self.dom.img+':first');
				_nowshow.s = true;
				_nowshow.css('z-index',11);
				$(_self.dom.btn).bind(_self.dom.e,function(){
						if($(this).hasClass(_self.dom.cls)){return false;}
						$(this).siblings().removeClass(_self.dom.cls);
						var i = $(this).addClass(_self.dom.cls).index();
						_self.index = i;
						var _showImg = $(_self.dom.img).eq(_self.index);
						_self.imgShow(_showImg);
						_nowshow.css('z-index',11);
						_showImg.stop().css({'z-index':10,'opacity':1}).show();
						_nowshow.fadeOut(300,function(){
							$(this).css('z-index',1);
							});
						_nowshow = _showImg;
						});
				$(_self.dom.img).parent().hover(function(e){
					clearTimeout(_self.timeout);
				},function(){
					_self.automatic();
				});
			},
imgShow:function(showImg){
			showImg.attr('i') && showImg.css('background','url('+ showImg.attr('i') +') no-repeat center').removeAttr('i');
			showImg.attr('c') && showImg.css('background-color',showImg.attr('c')).removeAttr('c');
		},
automatic:function(){
			  var _self = this;
			  if(_self.index >= $(_self.dom.btn).length - 1){_self.index = -1;}
			  clearTimeout(_self.timeout);
			  _self.timeout = setTimeout(function(){
					  $(_self.dom.btn).eq(_self.index + 1).trigger(_self.dom.e);
					  _self.automatic();
					  },_self.dom.t);
		  }
}

new Slide();
